Skip to content

Various refactors to the LTO handling code #143388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 17, 2025
Merged

Conversation

bjorn3
Copy link
Member

@bjorn3 bjorn3 commented Jul 3, 2025

In particular reducing the sharing of code paths between fat and thin-LTO and making the fat LTO implementation more self-contained. This also moves some autodiff handling out of cg_ssa into cg_llvm given that Enzyme only works with LLVM anyway and an implementation for another backend may do things entirely differently. This will also make it a bit easier to split LTO handling out of the coordinator thread main loop into a separate loop, which should reduce the complexity of the coordinator thread.

bjorn3 added 9 commits July 3, 2025 14:28
Most uses of it either contain a fat or thin lto module. Only
WorkItem::LTO could contain both, but splitting that enum variant
doesn't complicate things much.
As opposed to sending a message to the coordinator thread.
This will allow merging all fat LTO steps together. In addition it
reduces the amount of work done on the coordinator thread without
jobserver token.
@rustbot
Copy link
Collaborator

rustbot commented Jul 3, 2025

r? @compiler-errors

rustbot has assigned @compiler-errors.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. F-autodiff `#![feature(autodiff)]` S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 3, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 3, 2025

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

Some changes occurred in compiler/rustc_codegen_llvm/src/builder/autodiff.rs

cc @ZuseZ4

autodiff: autodiff_items.clone(),
},
0,
));
if cgcx.parallel {
helper.request_token();
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is necessary for fat LTO given that only a single thread will be doing LTO work and we have the implicit token anyway. It is pre-existing though and the token should be immediately yielded back to the jobserver if we indeed don't actually use it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My latest cleanup pr removes the clone, but you can land this pr first, as you say it didn't really hurt.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was actually talking about the helper.request_token() call.

@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Jul 16, 2025

📌 Commit 21026ca has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 16, 2025
fmease added a commit to fmease/rust that referenced this pull request Jul 16, 2025
…rrors

Various refactors to the LTO handling code

In particular reducing the sharing of code paths between fat and thin-LTO and making the fat LTO implementation more self-contained. This also moves some autodiff handling out of cg_ssa into cg_llvm given that Enzyme only works with LLVM anyway and an implementation for another backend may do things entirely differently. This will also make it a bit easier to split LTO handling out of the coordinator thread main loop into a separate loop, which should reduce the complexity of the coordinator thread.
bors added a commit that referenced this pull request Jul 17, 2025
Rollup of 15 pull requests

Successful merges:

 - #142304 (tests: Add `RUST_BACKTRACE` and `-Cpanic` revisions to `panic-main.rs` test)
 - #143388 (Various refactors to the LTO handling code)
 - #143409 (Enable xgot feature for mips64 musl targets)
 - #143592 (UWP: link ntdll functions using raw-dylib)
 - #143595 (add `const_make_global`; err for `const_allocate` ptrs if didn't call)
 - #143678 (Added error for invalid char cast)
 - #143820 (Fixed a core crate compilation failure when enabling the `optimize_for_size` feature on some targets)
 - #143829 (Trim `BorrowedCursor` API)
 - #143846 (pass --gc-sections if -Zexport-executable-symbols is enabled and improve tests)
 - #143851 (ci cleanup: rustdoc-gui-test now installs browser-ui-test)
 - #143856 (Linting public reexport of private dependencies)
 - #143895 (Dont collect assoc ty item bounds from trait where clause for host effect predicates)
 - #143922 (Improve path segment joining)
 - #143964 (Fix handling of SCRIPT_ARG in docker images)
 - #144016 (trait_sel: `MetaSized` always holds temporarily)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Jul 17, 2025
Rollup of 15 pull requests

Successful merges:

 - #142304 (tests: Add `RUST_BACKTRACE` and `-Cpanic` revisions to `panic-main.rs` test)
 - #143388 (Various refactors to the LTO handling code)
 - #143409 (Enable xgot feature for mips64 musl targets)
 - #143592 (UWP: link ntdll functions using raw-dylib)
 - #143595 (add `const_make_global`; err for `const_allocate` ptrs if didn't call)
 - #143678 (Added error for invalid char cast)
 - #143820 (Fixed a core crate compilation failure when enabling the `optimize_for_size` feature on some targets)
 - #143829 (Trim `BorrowedCursor` API)
 - #143851 (ci cleanup: rustdoc-gui-test now installs browser-ui-test)
 - #143856 (Linting public reexport of private dependencies)
 - #143895 (Dont collect assoc ty item bounds from trait where clause for host effect predicates)
 - #143922 (Improve path segment joining)
 - #143964 (Fix handling of SCRIPT_ARG in docker images)
 - #144002 (Update poison.rs)
 - #144016 (trait_sel: `MetaSized` always holds temporarily)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit be5f8f2 into rust-lang:master Jul 17, 2025
21 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jul 17, 2025
rust-timer added a commit that referenced this pull request Jul 17, 2025
Rollup merge of #143388 - bjorn3:lto_refactors, r=compiler-errors

Various refactors to the LTO handling code

In particular reducing the sharing of code paths between fat and thin-LTO and making the fat LTO implementation more self-contained. This also moves some autodiff handling out of cg_ssa into cg_llvm given that Enzyme only works with LLVM anyway and an implementation for another backend may do things entirely differently. This will also make it a bit easier to split LTO handling out of the coordinator thread main loop into a separate loop, which should reduce the complexity of the coordinator thread.
@bjorn3 bjorn3 deleted the lto_refactors branch July 17, 2025 09:07
rust-bors bot added a commit that referenced this pull request Jul 17, 2025
Various refactors to the LTO handling code (part 2)

Continuing from #143388 this removes a bit of dead code and moves the LTO symbol export calculation from individual backends to cg_ssa.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. F-autodiff `#![feature(autodiff)]` S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants